package org.ainlolcat.ctp.model.configuration;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: ain
 * Date: 04.09.12
 * Time: 14:57
 * To change this template use File | Settings | File Templates.
 */
public class Configuration {
    private List<ModuleDef> modules = new ArrayList<ModuleDef>();
    
    private Map<String, List<ModuleDef>> modules4source = new Hashtable<String, List<ModuleDef>>();
    private List<ModuleDef> dataSources;
    
    public List<ModuleDef> getSubscribers(String source){
        if (!modules4source.containsKey(source)) {
            List<ModuleDef> newGroup = new ArrayList<ModuleDef>();
            for (ModuleDef m : modules){
                if (m.sources.contains(source)) newGroup.add(m);
            }
            modules4source.put(source, newGroup);
        }
        return modules4source.get(source);
    }

    public List<ModuleDef> getDataSources(){
        if (dataSources != null && !dataSources.isEmpty()) return dataSources;
        List<ModuleDef> temp = new ArrayList<ModuleDef>();
        for (ModuleDef m : modules){
            if (m.sources == null || m.sources.isEmpty()) temp.add(m);
        }
        dataSources = temp;
        return dataSources;
    }
    
    public List<ModuleDef> getAllModules(){
        return modules;
    }
}
